<?php

namespace App\Models;

use App\Events\WorksAuthorsChangedEvent;
use Illuminate\Database\Eloquent\Model;
use App\Models\Works;

class WorksAuthor extends Model
{
    protected $table = 'works_author';
    
    public $timestamps = FALSE;
    
    public function authorInfo(){
        return $this->hasOne('App\Models\Student' , 'user_id', 'author_id')->withTrashed();
    }
    
    public function worksInfo(){
        return $this->hasOne('App\Models\Works' , 'id', 'works_id')->withTrashed();
    }

    protected static function boot(){
        parent::boot();
        self::created(function($model){
            \Event::fire( new WorksAuthorsChangedEvent($model));
        });
        self::deleted(function ($model){
            \Event::fire( new WorksAuthorsChangedEvent($model));
        });
    }
    

}
